<!DOCTYPE html>
<html>
<head lang="en">
	<title>找攻略</title>
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
	<link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
	<script src="/js/jquery/jquery.min.js"></script>
	<script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
	<link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
	<link rel="stylesheet" href="/css/reset.css"/>
	<link rel="stylesheet" href="/css/myStrategyComment.css"/>
	<script src="/js/plugins/jrender/jrender.min.js"></script>
	<link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
	<script src="/js/plugins/dialog2/dialog.min.js"></script>
	<script src="/js/plugins/form/jquery.form.js"></script>
	<script src="/js/common.js"></script>
	<script>
		$(function () {
		    //点击图片
            $(".imgs .rect").click(function () {
                img=$(this);
                $("#fileForm input[name='file']").click();
            })
            //提交图片后把图片显示到原图片的位置
            $("#fileForm input[name='file']").change(function () {
                if ($(this).val()) {
                    $("#fileForm").ajaxSubmit(function (data) {
                        img.html('<img src="'+data.url+'" width="100%">');
                    })
                }
            })

			//朋友圈对象
			var friendship={};
            //图片

            $("#submitBtn").click(function () {
                friendship.content=$(".comment [name=content]").val();
				var imgArr = $(".imgs img");
                console.log(imgArr);
                var temp = "";
				for(var i =0;i<imgArr.length;i++){
                    temp+=$(imgArr[i]).attr("src")+";";
				}
                friendship.images=temp;
                console.log(1);
                $.post("/friendships",friendship,function (data) {
                    console.log(2);
                    if (data.success) {
                        $(document).dialog({
                            overlayClose: true,
                            content: '发布成功',
                        });
                        location.href="/mine/dynamic.html"
                    }else{
                        $(document).dialog({
                            overlayClose: true,
                            content: data.msg,
                        });
                    }
                })
            })

		})
	</script>
</head>

<body>
<form id="fileForm" action="/images" method="post" enctype="multipart/form-data">
	<input type="file" name="file" id="file" style="display: none" accept="image/*">
</form>
<div class="search-head">
	<div class="row nav-search">
		<div class="col">
			<a href="javascript:window.history.go(-1)">
				<span><i class="fa fa-chevron-left" ></i></span>
			</a>
		</div>
		<div class="col">
			<span>发布朋友圈</span>
		</div>
		<div class="col"></div>
	</div>
</div>
<div class="comment">
		<textarea name="content" class="form-control" rows="5" placeholder="这一刻的想法..."></textarea>
	</div>
	<div class="container imgs ">
		<p>上传图片</p>
		<div class="row">
			<div class="col-3 rect">
				<span>上传</span>
			</div>
			<div class="col-3 rect">
				<span>上传</span>
			</div>
			<div class="col-3 rect">
				<span>上传</span>
			</div>
		</div>
	</div>
</div>
<div class="operation">
	<button class="btn" onclick="window.history.go(-1)">放弃发布</button>
	<button class="btn" id="submitBtn">发布动态</button>
</div>
</body>
</html>